package me.helllp.dake.generator.meta.core;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import com.squareup.javapoet.MethodSpec;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class SmartMethod {
	/**
	 * 入参信息
	 */
	private List<SmartParameter> parameters;
	
	/**
	 * 出参信息
	 */
	private SmartType returns;
	
	/**
	 * 名称
	 */
	private String name;
	
	/**
	 * 描述
	 */
	private String desc;
	
	public MethodSpec.Builder builder() {
		return MethodSpec.methodBuilder(name)
				.addParameters(
					Optional.ofNullable(parameters).map(item -> {
						return item.stream().map(parameter -> parameter.builder().build()).collect(Collectors.toList());
					}).orElse(Collections.emptyList()))
				.returns(returns.build());
	}
}
